package com.mzz.structure.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xushijian
 * @date 18/5/24 上午11:35
 */
public class WebSiteFactory {

    private static Map<String, WebSite> webSiteMap = new HashMap();

    //禁止外部创建
    private WebSiteFactory() {
    }

    //创建网页对象
    public static WebSite createWebSite(String type) {

        WebSite webSite = webSiteMap.get(type);

        if (webSite == null) {
            webSite = new ConcurrentWebSite(type);
            webSiteMap.put(type, webSite);
        }
        return webSite;
    }

    /**
     * 获取网页对象实例个数
     *
     * @return 获取对象个数
     */
    public static int webSiteCount() {
        return webSiteMap.size();
    }
}
